package com.framework.boc.response;

public class CommonResponse {

    /**
     * 状态码
     */
    private int code;

    /**
     * 描述
     */
    private String message;

    /**
     * 返回对象
     */
    private Object data;


    /**
     * 根据回复枚举创建回复对象
     * @param responseEnum      回复枚举
     * @param data              回复对象
     * @return                  通用回复对象
     */
    public static CommonResponse create(ResponseEnum responseEnum, Object data) {
        CommonResponse response = new CommonResponse();
        response.setCode(responseEnum.getCode());
        response.setMessage(responseEnum.getMessage());
        response.setData(data);
        return response;
    }

    /**
     * 获取成功通用回复对象
     * @param data      回复对象
     * @return
     */
    public static CommonResponse success(Object data) {
        return create(ResponseEnum.SUCCESS, data);
    }


    /**
     * 获取错误通用回复对象
     * @return
     */
    public static CommonResponse error() {
        return create(ResponseEnum.ERROR, null);
    }

    /**
     * 根据错误信息创建回复对象
     * @param errorMessage      错误信息
     * @return
     */
    public static CommonResponse error(String errorMessage) {
        CommonResponse response = error();
        response.setMessage(errorMessage);
        return response;
    }

    /**
     * 根据错误码和错误信息创建回复对象
     * @param code              错误码
     * @param errorMessage      错误信息
     * @return
     */
    public static CommonResponse error(int code, String errorMessage) {
        CommonResponse response = new CommonResponse();
        response.setCode(code);
        response.setMessage(errorMessage);
        return response;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
